# -*- coding:UTF-8 -*-

import wx
import logging
from src.bridge.getconfdata import ConfData
from src.gui.kanbanp import KanBanPanel
from src.gui.dayportp import DayPortPanel
from src.gui.setconfp import SetConfPanel

logging.basicConfig(filename="./log/kanban.log", filemode='w',
                    format='%(asctime)s : %(levelname)s : %(message)s',
                    level=logging.DEBUG)


def check_conf():
    cfd = ConfData()
    if cfd.config.sections() == ['base', 'ztinfo', 'db']:
        if cfd.config.options('base') == ['datacome', 'opt']:
            if cfd.config.options('ztinfo') == ['url', 'user', 'pwd', 'prdouct_cn', 'project_cn', 'product_plan',
                                                'project_version']:
                if cfd.config.options('db') == ['local', 'user', 'passwd', 'port', 'dbname']:
                    return True
                else:
                    wx.MessageBox("请检查 db 节点下的参数名称")
                    exit(1001)
                    return False
            else:
                wx.MessageBox("请检查 ztinfo 节点下的参数名称")
                exit(1002)
                return False
        else:
            wx.MessageBox("请检查 base 节点下的参数名称")
            exit(1003)
            return False
    else:
        wx.MessageBox("请检查config.ini文件中的节点名称是否为‘base ztinfo db'!")
        exit(1000)
        return False


# def get_conf_data():
#     if _check_conf():
#         listvalue = []
#         listvalue.append('数据库' if cfd.get_one_value(section='base', key='datacome') == '0' else '爬虫')
#         listvalue.append(cfd.get_one_value(section='ztinfo', key='user'))
#         listvalue.append(cfd.get_one_value(section='ztinfo', key='url'))
#         listvalue.append(cfd.get_one_value(section='ztinfo', key='prdouct_cn'))
#         listvalue.append(cfd.get_one_value(section='ztinfo', key='project_cn'))
#         listvalue.append(cfd.get_one_value(section='ztinfo', key='product_plan'))
#         listvalue.append(cfd.get_one_value(section='ztinfo', key='project_version'))
#         return listvalue
#     else:
#         return ['数据库', '', '', '', '', '', '']


if __name__ == '__main__':
    app = wx.App(clearSigInt=True)
    frame = wx.Frame(None, title="禅道看板", size=(990, 860))
    nb = wx.Notebook(frame)
    values = check_conf()
    if check_conf():
        nb.AddPage(KanBanPanel(nb), "看板")
        nb.AddPage(DayPortPanel(nb), "日报")
        nb.AddPage(SetConfPanel(nb), '设置')
        frame.Show(True)
        app.MainLoop()
    else:
        exit(0000)
